﻿using CIS.Common.Enums;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CIS.Client.Modules.Operation.Models
{
    public class JobModel : BindableBase
    {
        public JobModel()
        {
            PPIDList = new List<string>();
        }
        public bool IsHasGlass { get; set; }

        private bool isSelected;

        public bool IsSelected
        {
            get { return isSelected; }
            set 
            { 
                isSelected = value;
                SetJobStatus();
                RaisePropertyChanged(nameof(IsSelected)); 
            }
        }

        public int SlotNo {  get; set; }
        public string? ProductId {  get; set; }
        public string? LotId {  get; set; }

        private string? ppid;
        public string? PPID
        {
            get { return ppid; }
            set
            {
                ppid = value;
                RaisePropertyChanged(nameof(PPID));
            }
        }
        public string? Judge { get; set; }

        private JobState jobStatus;

        public JobState JobStatus
        {
            get { return jobStatus; }
            set { jobStatus = value; RaisePropertyChanged(nameof(JobStatus)); }
        }
        public string? WorkOrder { get; set; }
        public string? Category { get; set; }
        public string? ProductSpec { get; set; }
        public string? GlassType { get; set; }
        public Productype ProductType { get; set; }
        public string? Thinkness { get; set; }
        public string? ProductSize { get; set; }
        public string? OperationId { get; set; }
        public string? ProductSpecName { get; set; }
        public string? ProductFlowName { get; set; }
        public SlotStatus SlotState { get; set; }

        private List<string>? ppidList;
        public List<string>? PPIDList
        {
            get { return ppidList; }
            set
            {
                ppidList = value;
                RaisePropertyChanged(nameof(PPIDList));
            }
        }

        private void SetJobStatus()
        {
            if (IsSelected)
            {
                JobStatus = JobState.Selected;
                SlotState = SlotStatus.W;
            }
            else
            {
                JobStatus = JobState.Queued;
                SlotState = SlotStatus.S;
            }
        }
    }
}
